<?php


namespace App\Http\Controllers;

use Illuminate\Support\Facades\Validator;

class BaseController extends Controller
{
    const NEW_RESOURCES = 201; //进入成功
    const SUCCESS = 200; //成功
    const INVALID = 400; //字段非法
    const WRONG = 401; //错误
    const BAND = 403; //错误

    public function returnJson($data = [], $code = self::SUCCESS, $status = 'success', $message = null){
        $data['status'] = $status;
        if ($message != null) $data['message'] = $message;
        return response()->json($data, $code);
    }

    public function returnInvalid($violations = []){
        $data = [
            "status" => "invalid",
            "message" => "Request body is notvalid.",
            "violations" => $violations
        ];
        return response()->json($data, self::INVALID);
    }
}
